<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<c:if test="${empty blogList }">
	<c:redirect url="BlogServlet?task=queryBlog"></c:redirect>
</c:if>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="css/base.css" rel="stylesheet">
<link href="css/index.css" rel="stylesheet">
<link href="css/m.css" rel="stylesheet">
<script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<title>首页_个人博客</title>
</head>
<body>
	<header>
	<div class="logo">
		<c:if test="${empty sessionScope.username }">
			<h3>博客首页${sessionScope.reqUser }</h3>
		</c:if>
		<c:if test="${!empty sessionScope.username }">
			<h3>${sessionScope.username }的个人博客</h3>
		</c:if>

	</div>
	<nav id="nav">
	<ul>
		<li><a id="index" href="index.jsp">网站首页</a></li>
		<c:if test="${empty sessionScope.username }">
			<li><a href="user/myblog.jsp">个人博客</a></li>
		</c:if>
		<c:if test="${!empty sessionScope.username }">
			<li><a
				href="BlogServlet?task=queryMyBlog&author=${sessionScope.username }">个人博客</a></li>
		</c:if>
		<c:if test="${empty sessionScope.reqUser }">
			<li><a href="user/about.jsp">个人资料</a></li>
		</c:if>
		<c:if test="${empty sessionScope.username }">
		<li><a href="user/share.jsp">生活记录</a></li>
		</c:if>
		<c:if test="${!empty sessionScope.username }">
		<li><a href="ShareServlet?task=queryShareList&username=${sessionScope.reqUser }">生活记录</a></li>
		</c:if>
		<li><a href="user/message.jsp">留言板</a></li>
	</ul>
	</nav> <script>
		window.onload = function() {
			var obj = null;
			var As = document.getElementById('nav').getElementsByTagName('a');
			obj = As[0];
			for (i = 1; i < As.length; i++) {
				if (window.location.href.indexOf(As[i].href) >= 0)
					obj = As[i];
			}
			obj.id = 'selected'
		}
	</script> </header>
	<div class="mnav">
		<ul>
			<li><a id="index" href="index.jsp">网站首页</a></li>
			<c:if test="${empty sessionScope.username }">
				<li><a href="user/myblog.jsp">个人博客</a></li>
			</c:if>
			<c:if test="${!empty sessionScope.username }">
				<li><a
					href="BlogServlet?task=queryOtherBlog&author=${sessionScope.username }">个人博客</a></li>
			</c:if>
			<c:if test="${empty sessionScope.reqUser }">
				<li><a href="user/about.jsp">个人资料</a></li>
			</c:if>
			<li><a href="user/share.jsp">生活记录</a></li>
			<li><a href="user/message.jsp">留言板</a></li>
		</ul>
	</div>
	<article>
	<div class="l_box">
		<div class="about_me">
			<c:if test="${!empty sessionScope.username }">
				<h2>关于我</h2>
				<ul>
					<i><img src="/images/${sessionScope.userImg }"></i>
					<p>
						<b>姓名：${sessionScope.username }<span style="cursor: pointer;"
							onclick="logout()">[退出登录]</span></b><br> <b>性别：*</b><br> <b>联系电话：1*****</b>
					</p>
				</ul>
			</c:if>
			<c:if test="${empty sessionScope.username }">
				<h2>关于我</h2>
				<ul>
					<i><img src="images/timg.jpg"
						style="height: 80px; width: 120px"></i>
					<p>
						<b><a href="login.jsp">请登录</a></b>

					</p>
				</ul>
			</c:if>

		</div>

		<div class="search">
			<form action="BlogServlet?task=queryBlog" method="post"
				name="searchform" id="searchform">
				<input name="title" id="keyboard" class="input_text"
					value="请输入要搜索的文章标题" style="color: rgb(153, 153, 153);"
					onfocus="if(value=='请输入关键字词'){this.style.color='#000';value=''}"
					onblur="if(value==''){this.style.color='#999';value='请输入要搜索的文章标题'}"
					type="text"> <input name="show" value="title" type="hidden">
				<input name="tempid" value="1" type="hidden"> <input
					name="tbname" value="news" type="hidden"> <input
					name="Submit" class="input_submit" value="搜索" type="submit">
			</form>
		</div>
		<div class="fenlei">
			
		</div>
		<div class="tuijian">
			<h2>最新博客</h2>
			<ul>
				<c:forEach items="${newblogList}" var="newblog">

					<li><a class="article"
						href="BlogServlet?task=queryBlogById&id=${newblog.id }"
						title="${newblog.title }" id="${newblog.id }"> <c:if
								test="${fn:length(newblog.title)>10 }">
                         ${fn:substring(newblog.title, 0, 10)}...
                  </c:if> <c:if test="${fn:length(newblog.title)<=10 }">
                         ${newblog.title }
                   </c:if>
					</a><span style="font-size: 12px; font-weight: normal; float: right">阅读数
							<span id="count">${newblog.count }</span>
					</span></li>
				</c:forEach>

			</ul>
		</div>

		<div class="tuijian">
			<h2>热点博客</h2>
			<ul>
				<c:forEach items="${hotblogList}" var="hotblog">
					<li><a class="article"
						href="BlogServlet?task=queryBlogById&id=${hotblog.id }"
						title="${hotblog.title }" id="${hotblog.id }"> <c:if
								test="${fn:length(hotblog.title)>10 }">
                         ${fn:substring(hotblog.title, 0, 10)}...
                  </c:if> <c:if test="${fn:length(hotblog.title)<=10 }">
                         ${hotblog.title }
                   </c:if>
					</a><span style="font-size: 12px; font-weight: normal; float: right">阅读数
							<span id="count">${hotblog.count }</span>
					</span></li>
				</c:forEach>

			</ul>
		</div>
	</div>
	<div class="r_box">
		<c:forEach items="${blogList}" var="blog" varStatus="stas">
			<li>
				<h3>
					<a class="article"
						href="BlogServlet?task=queryBlogById&id=${blog.id }"
						id="${blog.id }">◤${blog.title }</a><br> <span
						style="font-size: 12px; font-weight: normal;">${blog.author }
						${blog.date } | 阅读数 <span id="count">${blog.count }</span>
					</span>
				</h3>
				<p>${content[stas.index]}</p>
			</li>
		</c:forEach>
		<div class="pagelist">${pageTools }</div>
	</div>
	</article>

	<footer>
	<p>
		Design by <a href="/" target="_blank">个人博客</a> <a
			href="/">ICP备号</a>
	</p>
	</footer>
	<script type="text/javascript">
		function logout() {
			window.location.href = "UserServlet?task=logout"
		}
	</script>

	<script type="text/javascript">
		$(".article").click(function() {
			var count = $("#count").text();
			var id = $(this).attr("id");
			var href = $(this).attr("href");
			$.ajax({
				type : "post",
				url : "BlogServlet",
				data : {
					"task" : "updateCount",
					"id" : id,
					"count" : count,
				},
				success : function(msg) {

				},

				error : function(error) {
					alert("error")
				}
			})
		})
	</script>
	<script type="text/javascript">
		$(function() {
			$
					.ajax({
						type : "post",
						url : "TypeServlet",
						data : {
							"task" : "queryTypeList",
						},
						success : function(msg) {
							var list = eval(msg);
							var str = "<h2>文章分类</h2><ul>";
							for (var i = 0; i < list.length; i++) {
								
								str += "<li><a href='BlogServlet?task=queryBlogByType&type="+list[i].type+"'>" + list[i].type
										+ "</a></li>"
							}
							str += "</ul>";
							$(".fenlei").append(str)
						},

					})
		})
	</script>
	<script type="text/javascript">
		$("#index").click(function() {
			window.location.href = "UserServlet?task=out"
		})
	</script>

</body>
</html>